package cn.xzqwjw.taskmanager.domain.pojo;

import cn.xzqwjw.taskmanager.common.validator.HttpMethodValidator;
import cn.xzqwjw.taskmanager.common.validator.ValidGroupUpdate;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author rush
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class SysPurview extends Model<SysPurview> implements Serializable {

  @TableField(exist = false)
  private static final long serialVersionUID = 1L;

  @Override
  public Serializable pkVal() {
    return this.id;
  }

  /**
   * 自动编号
   */
  @TableId(value = "id", type = IdType.AUTO)
  @NotNull(message = "id不能为空", groups = ValidGroupUpdate.class)
  private Integer id;

  /**
   * 权限名称（中文）
   */
  @NotBlank(message = "权限名称不能为空")
  @Length(max = 20, message = "name最多20个字符")
  private String label;

  /**
   * 权限标识符（英文）
   */
  @NotBlank(message = "权限标识符不能为空")
  @Length(max = 50, message = "code最多50个字符")
  private String code;

  /**
   * 服务器端的一个url资源
   */
  @Length(max = 200, message = "serverUrl最多200个字符")
  private String serverUrl = "";

  /**
   * 访问该条url资源需要的httpMethod
   */
  @Length(max = 50, message = "httpMethod最多50个字符")
  @HttpMethodValidator()
  private String httpMethod = "";

  /**
   * 访问该条url资源时body里需要携带的json格式的参数
   */
  @Length(max = 200, message = "bodyParams最多200个字符")
  private String bodyParams = "";

  /**
   * 关键字词
   */
  @NotEmpty(message = "keyword不能为空")
  @Length(max = 50, message = "keyword最多50个字符")
  private String tag;

  /**
   * 所有拥有此权限的管理员
   */
  @TableField(exist = false)
  private List<SysAdmin> adminList = new ArrayList<>();

  /**
   * 所有拥有此权限的角色
   */
  @TableField(exist = false)
  private List<SysRole> roleList = new ArrayList<>();

  /**
   * 此权限拥有的所有菜单资源
   */
  @TableField(exist = false)
  private List<SysFrontRoute> frontRouteList = new ArrayList<>();

}
